#include <gtkmm/window.h>
//#include <glibmm/refptr.h>

#include "ServiceManager.h"
#include "App.h"
#include "Service.h"

#include "ServiceConnection.h"
#include "ServiceInfomation.h"
#include "ServiceAppmanager.h"
#include "ServiceTaskmanager.h"
namespace Gnodroid {
    ServiceManager::ServiceManager () :
        Glib::ObjectBase("gnd_service_manager")
    {   
    }

    Service*
    ServiceManager::getService(ServiceId sId)
    {
        for(auto it = m_lsServiceList.begin();
            it != m_lsServiceList.end();
            it ++) {
            if ((*it)->getId() == sId) {
                return *it;
            }
        }
        return nullptr;

    }

    void
    ServiceManager::start()
    {
        //registe and start services
        Service* serviceConnection = new ServiceConnection();
        Service* serviceInfomation = new ServiceInfomation();
        Service* serviceAppmanager = new ServiceAppmanager();
        Service* serviceTaskmanager = new ServiceTaskmanager();

        __registeService(serviceConnection);
        __registeService(serviceInfomation);
        __registeService(serviceAppmanager);
        __registeService(serviceTaskmanager);

        serviceConnection->start();
        serviceInfomation->start();
        serviceAppmanager->start();
        serviceTaskmanager->start();
        //m_lsServiceList.push_back(serviceConnection);

    }

    void
    ServiceManager::stop()
    {
        //stop services
    }

    void
    ServiceManager::__registeService(Service* service)
    {
        m_lsServiceList.push_back(service);
    }
}


